﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DrCarDrive.DBService
{
    class FuelTopupService
    {
        private DrcardriveDB db;

        public FuelTopupService()
        {
            db = new DrcardriveDB();
        }

        public int save(tbl_fuel fuelTopup)
        {
            DateTime currentDateTime = DateTime.Now;
            
            fuelTopup.INSERT_TIME = currentDateTime;
            fuelTopup.UPDATE_TIME = currentDateTime;

            if (fuelTopup != null)
            {
                db.Fuel.Add(fuelTopup);
            }
            return db.SaveChanges();
        }

        internal int update(tbl_fuel fuelTopup)
        {
            DateTime currentDateTime = DateTime.Now;
            fuelTopup.UPDATE_TIME = currentDateTime;

            if (fuelTopup != null)
            {
                var original = db.Fuel.SingleOrDefault(p => p.ID.Equals(fuelTopup.ID));
                db.Entry(original).CurrentValues.SetValues(fuelTopup);
            }
            return db.SaveChanges();
        }

        public List<tbl_fuel> viewAll()
        {
            return db.Fuel.ToList();
        }

        internal List<tbl_fuel> viewByDriveID(string driveID)
        {
            return db.Fuel.Where(f => f.FKY_DRIVE.Equals(driveID)).ToList();
        }
    }
}
